package de.hsb.ai;

import jade.Boot;
import jade.core.Agent;

import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Map.Entry;

import javax.swing.UIManager;

import de.hsb.ai.agent.DemoDetective;
import de.hsb.ai.agent.ScotlandJadeManagementAgent;
import de.hsb.ai.agent.TeamDetectiveAgent.TeamDetective;
import de.hsb.ai.agent.analyzer.AnalyzerMasterDetective;
import de.hsb.ai.agent.jcau.StupidMisterXAgent;
import de.hsb.ai.agent.misterstar.MisterStar;
import de.hsb.ai.agent.misterx.MisterXAgent;
import de.hsb.ai.agent.jcau.*;

public class Main {
	
	private static org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(Main.class);

	
	static {
		try {
			UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
		} catch (Exception e) {
			logger.error("Setting L&F failed", e);
		}
	}

	/**
	 * Main program.
	 * @param args
	 */
	public static void main(String[] args) {
		Map<String, Class<? extends Agent>> agents = new LinkedHashMap<String, Class<? extends Agent>>(4);
		agents.put("manager", ScotlandJadeManagementAgent.class);
		agents.put("stupid", StupidMisterXAgent.class);
		agents.put(AnalyzerMasterDetective.LOCAL_NAME, AnalyzerMasterDetective.class);
		agents.put("demo1", DemoDetective.class);
		agents.put("demo2", DemoDetective.class);
		agents.put("demo3", DemoDetective.class);
		agents.put("jcauDetectiveTactic1_1", EstimatingDetectiveTac1.class);
		agents.put("jcauDetectiveTactic1_2", EstimatingDetectiveTac1.class);
		agents.put("jcauDetectiveTactic1_3", EstimatingDetectiveTac1.class);
		agents.put("jcauDetectiveTactic2_1", EstimatingDetectiveTac2.class);
		agents.put("jcauDetectiveTactic2_2", EstimatingDetectiveTac2.class);
		agents.put("jcauDetectiveTactic2_3", EstimatingDetectiveTac2.class);
		agents.put("jcauDetectiveTactic3_1", EstimatingDetectiveTac3.class);
		agents.put("jcauDetectiveTactic3_2", EstimatingDetectiveTac3.class);
		agents.put("jcauDetectiveTactic3_3", EstimatingDetectiveTac3.class);
		
		agents.put("team1", TeamDetective.class);
		agents.put("demo3", DemoDetective.class);
		agents.put("demo4", DemoDetective.class);
		agents.put("demo5", DemoDetective.class);
		agents.put("TeamDetective1", TeamDetective.class);
		agents.put("TeamDetective2", TeamDetective.class);
		agents.put("TeamDetective3", TeamDetective.class);
		agents.put("TeamDetective4", TeamDetective.class);
		agents.put("TeamDetective5", TeamDetective.class);
		agents.put("MrX", MisterXAgent.class);
		agents.put("MrStar", MisterStar.class);
		
		String[] jade_args = {"-name Scotlandyard", "-services jade.tools.rma.rma,jade.domain.df", stringifyAgents(agents)};
		
		Boot.main(jade_args);
	}

	private static String stringifyAgents(Map<String, Class<? extends Agent>> agents) {
		StringBuilder builder = new StringBuilder();
		for (Entry<String, Class<? extends Agent>> e : agents.entrySet()) {
			builder.append(e.getKey()).append(':').append(e.getValue().getCanonicalName()).append(';');
		}
		logger.info(builder.toString());
		return builder.toString();
	}

}

